Skip to content

Add import sys.exit to optimum_cli.py - #2325

Closed
rasapala wants to merge 1 commit into
huggingface:mainfrom
rasapala:optimum_exit_import_fix
Closed

rasapala wants to merge 1 commit into
huggingface:mainfrom
rasapala:optimum_exit_import_fix

Conversation

@rasapala

Copy link
Copy Markdown

Add import sys.exit to optimum_cli.py.
optimum_cli.exe when run with no parameters throws error missing name: exit.

@IlyasMoutawwakil

Copy link
Copy Markdown
Member

@rasapala where do you get this error ? windows ?

@rasapala

Copy link
Copy Markdown
Author

Yes it was discovered on windows.

@IlyasMoutawwakil

Copy link
Copy Markdown
Member

@rasapala and why would anyone run optimum cli with no params ? 馃槄
whats being fixed here exactly, please elaborate

@rasapala

Copy link
Copy Markdown
Author

I have run into the problem while checking optimum-cli installation. First command to run to check if its available in env PATH is to run optimum-cli command. Then the problem occurred. I have worked around it and checked optimum-cli -h and everyone can do that but I wanted to let you know that this scenario may happen and this is a fix for it.

@IlyasMoutawwakil

Copy link
Copy Markdown
Member

I just pip installed optimum in my windows env and ran optimum-cli.exe and it worked fine

Successfully installed MarkupSafe-3.0.2 filelock-3.19.1 fsspec-2025.9.0 huggingface_hub-0.34.4 jinja2-3.1.6 mpmath-1.3.0 networkx-3.5 optimum-1.27.0 pyyaml-6.0.2 regex-2025.9.1 safetensors-0.6.2 setuptools-80.9.0 sympy-1.14.0 tokenizers-0.22.0 torch-2.8.0 transformers-4.56.1
PS C:\Users\ilyas> optimum-cli.exe
usage: optimum-cli

positional arguments:
  {export,env}
    export      Export PyTorch and TensorFlow models to several format.
    env         Get information about the environment used.

options:
  -h, --help    show this help message and exit
PS C:\Users\ilyas> 

is this related to a specific python version ?

@rasapala

Copy link
Copy Markdown
Author

Yes, it fails on newer python version like 3.12.10.

@IlyasMoutawwakil

Copy link
Copy Markdown
Member

sorry I wasn't able to reproduce..
I did the following on my windows machine:

uv venv --python 3.12.10
.venv\Scripts\activate
uv pip install optimum
optimum-cli

and didn't get any errors 馃

@rasapala

rasapala commented Oct 7, 2025

Copy link
Copy Markdown
Author

I think the problem occurs when you use standard Python installation procedures with python installer.
https://www.python.org/ftp/python/3.12.10/python-3.12.10-amd64.exe

@IlyasMoutawwakil

IlyasMoutawwakil commented Oct 7, 2025 •

Copy link
Copy Markdown
Member

hmm i wasn't able to reproduce, but was able to find references to this issue in the python org / cpython repo python/cpython#73089 what I suggest to do is to import sys and use sys.exit() in the cli tool instead of exit(), following the answer in https://stackoverflow.com/questions/19747371/python-exit-commands-why-so-many-and-when-should-each-be-used

@github-actions

github-actions Bot commented Jan 6, 2026

Copy link
Copy Markdown

This PR has been marked as stale because it has been open for 90 days with no activity. This thread will be automatically closed in 30 days if no further activity occurs.

@github-actions github-actions Bot added the Stale label Jan 6, 2026
@github-actions github-actions Bot closed this Feb 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants